function BxUniversalGrid(e){"use strict";this.oColsMeta={};this.oColsNames={};this.customNames={};this.columnsSizes={};this.oEditData={};this.oSaveData={};this.oOptions={};this.oVisibleCols={};this.vars={};this.menu=null;this.settingsMenu=[];this.filterMenu=[];this.checkBoxCount=0;this.bColsChanged=false;this.bViewsChanged=false;this.oFilterRows={};this.activeRow=null;this.hasActions=false;this.editMode=false;this.resizeMeta={};this.table_id=e+"_table";this.grid_id=e;var t=this;var i=null;var s=false;this.InitTable=function(){i=BX.Main.gridManager.getById(t.grid_id).instance;this.checkBoxCount=0;var e=i.getTable();if(!e||e.rows.length<1||e.rows[0].cells.length<1){return}var s=e.rows[0].cells;for(var a=0;a<s.length;a++){if(BX.hasClass(s[a],"main-grid-cell-action")||BX.hasClass(s[a],"main-grid-cell-checkbox")){s[a].__fixed=true;continue}var n=BX.findChildByClassName(s[a],"main-grid-cell-head-container",false);BX.addClass(n,"main-grid-cell-head-dragable");BX.removeClass(s[a],"main-grid-cell-sortable")}this.initResizeMeta();this.toogleFader();BX.bind(window,"resize",BX.delegate(this.toogleFader,this));BX.bind(e.parentNode,"scroll",this.toogleFader);if(i.getParam("ALLOW_COLUMNS_RESIZE")){for(var a=0;a<s.length;a++){if(s[a].__fixed){continue}var l=BX.findChildByClassName(s[a],"main-grid-resize-button");if(l){l.onbxdragstart=t.resizeColumnStart;l.onbxdragstop=t.resizeColumnStop;l.onbxdrag=t.resizeColumn;jsDD.registerObject(l)}}var r=function(){var e=i.getPinHeader().getFixedTable();var s=BX.findChild(e,{"class":"main-grid-resize-button"},true,true);s.forEach(function(e){e.onbxdragstart=t.resizeColumnStart;e.onbxdragstop=t.resizeColumnStop;e.onbxdrag=t.resizeColumn;jsDD.registerObject(e)})};BX.addCustomEvent(window,"Grid::headerPinned",r);BX.addCustomEvent(window,"Grid::updated",r)}};this.CheckColumn=function(e,t){var s;var a=this.menu.GetMenuByItemId(t.id);var n=!(a.GetItemInfo(t).ICON=="checked");a.SetItemIcon(t,n?"checked":"");if(e){s=i.getUserOptions().getCurrentOptions().columns.split(",");if(BX.type.isArray(s)&&BX.type.isNotEmptyString(e)){if(s.some(function(t){return t===e})){s=s.filter(function(t){return t!==e});BX.removeClass("menu_"+i.getContainerId()+"_columns_item_","checked")}else{s.unshift(e);BX.addClass("menu_"+i.getContainerId()+"_columns_item_","checked")}}i.tableFade();i.getUserOptions().setColumns(s,function(){i.reloadTable();BX.onCustomEvent(i.getContainer(),"Grid::columnsChanged",[i])})}};this.reinitColumnSize=function(e,t){var i=this.GetColumnId(e);if(i!==false){var s=BX(this.table_id);var a=s.offsetWidth;var n=s.rows[0].cells[i];var l=BX.findChildByClassName(n,"main-grid-cell-head-container",false);l.style.height="";BX.removeClass(l,"main-grid-cell-head-dragable");n.style.width="";n.style.width=n.offsetWidth+"px";BX.addClass(l,"main-grid-cell-head-dragable");l.style.height=s.rows[0].cells[0].clientHeight+"px";if(t){n.setAttribute("data-resize",1)}}};this.initResizeMeta=function(){var e=i.getTable();var t=e.rows[0].cells;this.resizeMeta.fixed=0;this.resizeMeta.minPx=e.offsetWidth;var s=false;for(var a=0;a<t.length;a++){var n=BX.width(t[a]);if(t[a].__fixed){this.resizeMeta.fixed+=n;continue}if(n>0){var l=t[a].getAttribute("data-name");if(this.resizeMeta.columns[l]!=n){s=true}this.resizeMeta.columns[l]=n}}if(s){this.resizeMeta.expand=1}};this.reinitResizeMeta=function(){var e=BX(t.table_id);var i=e.rows[0].cells;for(var s=0;s<i.length;s++){if(i[s].__fixed){continue}if(i[s].offsetWidth>0){var a=i[s].getAttribute("data-name");t.resizeMeta.columns[a]=i[s].offsetWidth}}var n=e.offsetWidth;var l=e.parentNode.clientWidth;t.resizeMeta.minPx=n;t.resizeMeta.expand=n<l?n/l:1;t.saveColumnsSizes()};this.toogleFader=function(){var e=BX.Main.gridManager.getById(t.grid_id).instance;var i=e.getTable();var s=e.getScrollContainer();if(i.offsetWidth>s.clientWidth){if(s.scrollLeft>0){BX.addClass(s.parentNode,"main-grid-fade-left")}else{BX.removeClass(s.parentNode,"main-grid-fade-left")}if(i.offsetWidth>s.scrollLeft+s.clientWidth){BX.addClass(s.parentNode,"main-grid-fade-right")}else{BX.removeClass(s.parentNode,"main-grid-fade-right")}}else{BX.removeClass(s.parentNode,"main-grid-fade-left");BX.removeClass(s.parentNode,"main-grid-fade-right")}};this.OnRowContext=function(e){if(!t.menu){return}if(!e){e=window.event}if(!phpVars.opt_context_ctrl&&e.ctrlKey||phpVars.opt_context_ctrl&&!e.ctrlKey){return}var i;if(e.target){i=e.target}else if(e.srcElement){i=e.srcElement}var s=i;while(s&&!(s.tagName&&s.tagName.match(/(th|td)/i)&&s.oncontextmenu)){s=BX.findParent(s,{tagName:/(th|td)/i})}var a=null;if(s&&s.oncontextmenu){a=s.oncontextmenu();a[a.length]={SEPARATOR:true}}s=i;while(s&&!(s.tagName&&s.tagName.toUpperCase()==="TR"&&s.oncontextmenu)){s=jsUtils.FindParentObject(s,"tr")}var n=t.menu;n.PopupHide();t.activeRow=s;if(t.activeRow&&!BX.hasClass(s,"main-grid-row-head")){t.activeRow.className+=" active"}n.OnClose=function(){if(t.activeRow){t.activeRow.className=t.activeRow.className.replace(/\s*active/i,"");t.activeRow=null}};var l=BX.util.array_merge(a,s.oncontextmenu());if(l.length==0){return}n.SetItems(l);n.BuildItems();var r=jsUtils.GetWindowScrollPos();var o=e.clientX+r.scrollLeft;var d=e.clientY+r.scrollTop;var h={};h.left=h.right=o;h.top=h.bottom=d;n.PopupShow(h);e.returnValue=false;if(e.preventDefault){e.preventDefault()}};this.ShowActionMenu=function(e,i){t.menu.PopupHide();t.activeRow=jsUtils.FindParentObject(e,"tr");if(t.activeRow){t.activeRow.className+=" active"}var s=BX("datarow_"+this.table_id+"_"+i);var a=BX.data(s,"actions");if(s&&a){var n=JSON.parse(a);if(n&&n.length>0){t.menu.ShowMenu(e,n,false,false,function(){if(t.activeRow){t.activeRow.className=t.activeRow.className.replace(/\s*active/i,"");t.activeRow=null}})}}};this.SelectRow=function(e,t){t=t?t:window.event;var i=BX.findParent(e,{className:"main-grid-row"});var a=document.getElementById(this.table_id+"_selected_span");var n=parseInt(a.innerHTML);var l=[i];if(t&&t.shiftKey&&s&&s!==i){var r=document.getElementById(this.table_id);for(var o=Math.min(s.rowIndex,i.rowIndex)+1;o<Math.max(s.rowIndex,i.rowIndex);o++){l.push(r.rows[o])}if(BX.findChildByClassName(s.cells[0],"main-grid-checkbox").checked){l.push(s)}}for(var o in l){var d=BX.findChildByClassName(l[o].cells[0],"main-grid-checkbox");if(d&&(e===d||d.checked!==e.checked)){d.checked=e.checked;if(e.checked){BX.addClass(l[o],"main-grid-row-checked");n++}else{BX.removeClass(l[o],"main-grid-row-checked");n--}}}a.innerHTML=n.toString();var h=BX(this.table_id+"_check_all");h.checked=this.checkBoxCount>0&&n===this.checkBoxCount;s=i};this.SelectAllRows=function(e){};this.EnableActions=function(){var e=document.forms["form_"+this.table_id];if(!e)return;var t=this.IsActionEnabled();var i=this.IsActionEnabled("edit");var s=BX("edit_button_"+this.table_id);var a=BX("delete_button_"+this.table_id);if(e.apply){e.apply.disabled=!t;BX[t?"removeClass":"addClass"](e.apply,"webform-button-disable")}if(s)BX[i?"removeClass":"addClass"](s,"main-grid-control-panel-action-icon-disable");if(a)BX[t?"removeClass":"addClass"](a,"main-grid-control-panel-action-icon-disable")};this.IsActionEnabled=function(e){var t=document.forms["form_"+this.table_id];if(!t)return;var i=false;var s=document.getElementById(this.table_id+"_selected_span");if(s&&parseInt(s.innerHTML)>0)i=true;var a=t["action_all_rows_"+this.table_id];if(e=="edit")return!(a&&a.checked)&&i;else return a&&a.checked||i};this.SwitchActionButtons=function(e){var t=BX("bx_grid_"+this.table_id+"_action_buttons");var i=t;while(i=jsUtils.FindNextSibling(i,"div"))i.style.display=e?"none":"";t.style.display=e?"":"none"};this.ActionEdit=function(){if(this.IsActionEnabled("edit")){var e=document.forms["form_"+this.table_id];if(!e)return;this.editMode=true;this.SwitchActionButtons(true);var i=e["ID[]"];if(!i.length)i=new Array(i);for(var s=0;s<i.length;s++){var a=i[s];if(a.checked){var n=jsUtils.FindParentObject(a,"tr");BX.denyEvent(n,"dblclick");var l=jsUtils.FindParentObject(a,"td");l=jsUtils.FindNextSibling(l,"td");if(BX.hasClass(l,"main-grid-cell-action"))l=jsUtils.FindNextSibling(l,"td");var r=a.value;this.oSaveData[r]={};for(var o in this.oVisibleCols){if(this.oVisibleCols[o]==true&&this.oColsMeta[o].editable==true&&this.oEditData[r][o]!==false){this.oSaveData[r][o]=l.innerHTML;l.innerHTML="";var d=this.oEditData[r][o];var h="FIELDS["+r+"]["+o+"]";var c=BX.create("SPAN",{props:{className:"main-grid-cell-content"}});switch(this.oColsMeta[o].type){case"checkbox":c.appendChild(BX.create("INPUT",{props:{type:"hidden",name:h,value:"N"}}));c.appendChild(BX.create("INPUT",{props:{className:"main-grid-cell-content-edit",type:"checkbox",name:h,value:"Y",checked:d=="Y",defaultChecked:d=="Y"}}));break;case"list":var f=[];for(var v in this.oColsMeta[o].items){f[f.length]=BX.create("OPTION",{props:{value:v,selected:v==d},text:this.oColsMeta[o].items[v]})}c.appendChild(BX.create("SELECT",{props:{className:"main-grid-cell-content-edit",name:h},children:f}));break;case"date":var _={props:{className:"main-grid-cell-content-edit",type:"text",name:h,value:d,size:this.oColsMeta[o].size?this.oColsMeta[o].size:20},style:{paddingRight:"20px"}};if(this.oColsMeta[o].size)_.props.size=this.oColsMeta[o].size;else _.style.width="100%";c.appendChild(BX.create("INPUT",_));c.appendChild(BX.create("A",{props:{href:"javascript:void(0);",title:this.vars.mess.calend_title},style:{border:"none",position:"relative",right:"22px"},children:[BX.create("IMG",{props:{className:"calendar-icon",src:this.vars.calendar_image,alt:this.vars.mess.calend_title,onclick:function(e){return function(){BX.calendar({node:this,field:e,bTime:true,currentTime:t.vars.server_time})}}(h),onmouseover:function(){BX.addClass(this,"calendar-icon-hover")},onmouseout:function(){BX.removeClass(this,"calendar-icon-hover")}}})]}));BX.addClass(c,"main-grid-cell-text-line");break;case"textarea":var _={props:{className:"main-grid-cell-content-edit",name:h},text:d};if(this.oColsMeta[o].cols)_.props.cols=this.oColsMeta[o].cols;else _.style={width:"100%"};if(this.oColsMeta[o].rows)_.props.rows=this.oColsMeta[o].rows;if(this.oColsMeta[o].maxlength)_.props.maxLength=this.oColsMeta[o].maxlength;c.appendChild(BX.create("TEXTAREA",_));break;case"file":c.appendChild(BX.create("INPUT",{props:{className:"main-grid-cell-content-edit",type:"file",name:h}}));break;default:var _={props:{className:"main-grid-cell-content-edit",type:"text",name:h,value:d}};if(this.oColsMeta[o].size)_.props.size=this.oColsMeta[o].size;else _.style={width:"100%"};if(this.oColsMeta[o].maxlength)_.props.maxLength=this.oColsMeta[o].maxlength;c.appendChild(BX.create("INPUT",_));break}l.appendChild(c)}l=jsUtils.FindNextSibling(l,"td")}}a.disabled=true}BX(this.table_id+"_check_all").disabled=true;e.elements["action_button_"+this.table_id].value="edit"}};this.ActionCancel=function(){var e=document.forms["form_"+this.table_id];if(!e)return;this.editMode=false;this.SwitchActionButtons(false);var t=e["ID[]"];if(!t.length)t=new Array(t);for(var i=0;i<t.length;i++){var s=t[i];if(s.checked){var a=jsUtils.FindParentObject(s,"tr");BX.allowEvent(a,"dblclick");var n=jsUtils.FindParentObject(s,"td");n=jsUtils.FindNextSibling(n,"td");if(BX.hasClass(n,"main-grid-cell-action"))n=jsUtils.FindNextSibling(n,"td");var l=s.value;for(var r in this.oVisibleCols){if(typeof this.oSaveData[l][r]!="undefined")n.innerHTML=this.oSaveData[l][r];n=jsUtils.FindNextSibling(n,"td")}}}this.toggleCheckboxes();e.elements["action_button_"+this.table_id].value=""};this.ActionDelete=function(){var e=document.forms["form_"+this.table_id];if(!e)return;e.elements["action_button_"+this.table_id].value="delete";BX.submit(e)};this.ForAllClick=function(e){if(e.checked&&!confirm(this.vars.mess.for_all_confirm)){e.checked=false;return}var t=e.form["ID[]"];if(t){if(!t.length)t=new Array(t);for(var i=0;i<t.length;i++){if(t[i].getAttribute("data-disabled"))continue;t[i].disabled=e.checked}}BX(this.table_id+"_check_all").disabled=e.checked;this.editMode=e.checked;this.EnableActions()};this.Sort=function(e,i,s,a,n){var l;if(s==""){var r=null,o=false;if(n.length>0)r=n[0];if(!r)r=window.event;if(r)o=r.ctrlKey;l=o?a=="acs"?"desc":"asc":a}else if(s=="asc")l="desc";else l="asc";e+=l;BX.ajax.get("/bitrix/components"+t.vars.component_path+"/settings.ajax.php?GRID_ID="+t.table_id+"&action=savesort&by="+i+"&order="+l+"&sessid="+t.vars.sessid,function(){t.Reload(e)})};this.GetColumnId=function(e){var t=false;var i=BX(this.table_id);for(var s=0;s<i.rows[0].cells.length;s++){if(i.rows[0].cells[s].getAttribute("data-name")==e){t=s;break}}return t};this.animation=function(e,i,s,a){t.animation.stop(e);var n=function(){e.__animation.step++;var i=e.__animation;for(var s in i.props){var a=i.props[s];e.style[s]=a.from*1+(a.to-a.from)*i.step/i.steps+a.unit}if(i.step>=i.steps)t.animation.stop(e)};e.__animation={props:i,steps:Math.round(s/10),step:0,callback:a};e.__animation.interval=setInterval(n,s/e.__animation.steps)};this.animation.stop=function(e){if(e.__animation&&e.__animation.interval){e.__animation.interval=clearInterval(e.__animation.interval);if(e.__animation.callback)e.__animation.callback()}};this.toogleColumnCells=function(e,i,s){var a=BX(t.table_id);for(var n=0;n<a.rows.length;n++){var l=a.rows[n].cells;if(l[e]){l[e].style.display=i?"":"none";var r=BX.findChildByClassName(l[e],"main-grid-cell-content",false);if(r&&r.style)r.style.width=s?r.clientWidth+"px":""}}};this.toggleCheckboxes=function(){var e=BX(this.table_id);for(var t=1;t<e.rows.length;t++){if(BX.hasClass(e.rows[t],"main-grid-data-row")){var i=BX.findChildByClassName(e.rows[t].cells[0],"main-grid-checkbox");var s=i.value;var a=false;if(this.hasActions){if(!i.getAttribute("data-disabled"))a=true}else if(typeof this.oEditData[s]!="undefined"){for(var n in this.oVisibleCols){if(this.oVisibleCols[n]&&this.oColsMeta[n].editable&&this.oEditData[s][n]!==false)a=true}}if(a){if(i.getAttribute("data-disabled"))this.checkBoxCount++;i.disabled=this.editMode;i.removeAttribute("data-disabled")}else{if(!i.getAttribute("data-disabled"))this.checkBoxCount--;i.disabled=true;i.setAttribute("data-disabled",1)}}}if(this.checkBoxCount==0){BX(this.table_id+"_check_all").disabled=true;if(!this.editMode){for(var t=1;t<e.rows.length;t++){if(BX.hasClass(e.rows[t],"main-grid-data-row")){var i=BX.findChildByClassName(e.rows[t].cells[0],"main-grid-checkbox");if(i.checked){i.checked=false;this.SelectRow(i)}}}BX(this.table_id+"_action_bar_fade").style.display=""}}else{if(!this.editMode)BX(this.table_id+"_check_all").disabled=false;BX(this.table_id+"_action_bar_fade").style.display="none"}};this.SaveColumns=function(e,i){var s="";if(e){s=e}else{if(!t.bColsChanged)return;for(var a in t.oVisibleCols)if(t.oVisibleCols[a])s+=(s!=""?",":"")+a}t.oOptions.views[t.oOptions.current_view].columns=s;if(t.vars.user_authorized){BX.ajax.get("/bitrix/components"+t.vars.component_path+"/settings.ajax.php",{GRID_ID:t.table_id,action:"showcolumns",columns:s,sessid:t.vars.sessid},i)}};this.saveColumnsSizes=function(){i.getUserOptions().setColumnSizes(t.resizeMeta.columns,t.resizeMeta.expand)};this.Reload=function(e){var i=BX.Main.gridManager.getById(t.grid_id).instance;var s=i.getScrollContainer();var a;jsDD.Disable();if(!e){e=this.vars.current_url[this.vars.current_url.length-1]}if(this.vars.ajax.AJAX_ID!=""){a=BX.ajax.insertToNode(e+(e.indexOf("?")==-1?"?":"&")+"bxajaxid="+this.vars.ajax.AJAX_ID,"comp_"+this.vars.ajax.AJAX_ID);a.onprogress=function(){t.scrollContainerLeft=s.scrollLeft};a.onload=function(){i.getScrollContainer().scrollLeft=t.scrollContainerLeft;i.reloadTable()}}else{window.location=e}};this.SetView=function(e){var i=t.oOptions.views[e].saved_filter;var s=i&&t.oOptions.filters[i]?function(){t.ApplyFilter(i)}:function(){t.Reload()};BX.ajax.get("/bitrix/components"+t.vars.component_path+"/settings.ajax.php?GRID_ID="+t.table_id+"&action=setview&view_id="+e+"&sessid="+t.vars.sessid,s)};this.EditCurrentView=function(){this.ShowSettings(this.oOptions.views[this.oOptions.current_view],function(){t.SaveSettings(t.oOptions.current_view,true)})};this.AddView=function(){var e="view_"+Math.round(Math.random()*1e6);var i={};for(var s in this.oOptions.views[this.oOptions.current_view])i[s]=this.oOptions.views[this.oOptions.current_view][s];i.name=this.vars.mess.viewsNewView;this.ShowSettings(i,function(){var i=t.SaveSettings(e);t.oOptions.views[e]={name:i.name,columns:i.columns,sort_by:i.sort_by,sort_order:i.sort_order,page_size:i.page_size,saved_filter:i.saved_filter,custom_names:i.custom_names,columns_sizes:i.columns_sizes};t.bViewsChanged=true;var s=document["views_"+t.table_id];s.views_list.options[s.views_list.length]=new Option(i.name!=""?i.name:t.vars.mess.viewsNoName,e,true,true)})};this.EditView=function(e){this.ShowSettings(this.oOptions.views[e],function(){var i=t.SaveSettings(e);t.oOptions.views[e]={name:i.name,columns:i.columns,sort_by:i.sort_by,sort_order:i.sort_order,page_size:i.page_size,saved_filter:i.saved_filter,custom_names:i.custom_names,columns_sizes:i.columns_sizes};t.bViewsChanged=true;var s=document["views_"+t.table_id];s.views_list.options[s.views_list.selectedIndex].text=i.name!=""?i.name:t.vars.mess.viewsNoName})};this.DeleteView=function(e){if(!confirm(this.vars.mess.viewsDelete))return;var i=document["views_"+this.table_id];var s=i.views_list.selectedIndex;i.views_list.remove(s);i.views_list.selectedIndex=s<i.views_list.length?s:i.views_list.length-1;this.bViewsChanged=true;BX.ajax.get("/bitrix/components"+this.vars.component_path+"/settings.ajax.php?GRID_ID="+this.table_id+"&action=delview&view_id="+e+"&sessid="+t.vars.sessid)};this.ShowSettings=function(e,t){var i=false;if(!window["settingsDialog"+this.table_id]){window["settingsDialog"+this.table_id]=new BX.CDialog({content:'<form name="settings_'+this.table_id+'"></form>',title:this.vars.mess.settingsTitle,width:this.vars.settingWndSize.width,height:this.vars.settingWndSize.height,resize_id:"InterfaceGridSettingWnd"});i=true}window["settingsDialog"+this.table_id].ClearButtons();window["settingsDialog"+this.table_id].SetButtons([{title:this.vars.mess.settingsSave,action:function(){t();this.parentWindow.Close()}},BX.CDialog.prototype.btnCancel]);window["settingsDialog"+this.table_id].Show();var s=document["settings_"+this.table_id];if(i)s.appendChild(BX("view_settings_"+this.table_id));this.customNames=e.custom_names?e.custom_names:{};this.columnsSizes=e.columns_sizes?e.columns_sizes:{};s.view_name.focus();s.view_name.value=e.name;var a=[];if(e.columns!=""){a=e.columns.split(",")}else{for(var n in this.oVisibleCols){if(this.oVisibleCols[n])a[a.length]=n}}var l={},r;for(n=0,r=a.length;n<r;n++)l[a[n]]=true;jsSelectUtils.deleteAllOptions(s.view_all_cols);for(n in this.oColsNames){if(!l[n]){var o=this.customNames[n]?this.customNames[n]+" ("+this.oColsNames[n]+")":this.oColsNames[n];s.view_all_cols.options[s.view_all_cols.length]=new Option(o,n,false,false)}}jsSelectUtils.deleteAllOptions(s.view_cols);for(n in l){o=this.customNames[n]?this.customNames[n]+" ("+this.oColsNames[n]+")":this.oColsNames[n];s.view_cols.options[s.view_cols.length]=new Option(o,n,false,false)}s.reset_columns_sizes.checked=false;jsSelectUtils.selectOption(s.view_sort_by,e.sort_by);jsSelectUtils.selectOption(s.view_sort_order,e.sort_order);jsSelectUtils.selectOption(s.view_page_size,e.page_size);jsSelectUtils.deleteAllOptions(s.view_filters);s.view_filters.options[0]=new Option(this.vars.mess.viewsFilter,"");for(n in this.oOptions.filters)s.view_filters.options[s.view_filters.length]=new Option(this.oOptions.filters[n].name,n,n==e.saved_filter,n==e.saved_filter);if(s.set_default_settings){s.set_default_settings.checked=false;s.delete_users_settings.checked=false;s.delete_users_settings.disabled=true}s.up_btn.disabled=s.down_btn.disabled=s.rename_btn.disabled=s.add_btn.disabled=s.del_btn.disabled=true};this.RenameColumn=function(){var e=false;if(!window["renameDialog"+this.table_id]){window["renameDialog"+this.table_id]=new BX.CDialog({content:'<form name="rename_'+this.table_id+'"></form>',title:this.vars.mess.renameTitle,width:this.vars.renameWndSize.width,height:this.vars.renameWndSize.height,resize_id:"InterfaceGridRenameWnd",buttons:[{title:this.vars.mess.settingsSave,action:function(){var e=s.view_cols.value;var a=i.col_name.value;if(a.length>0){t.customNames[e]=a;a=a+" ("+t.oColsNames[e]+")"}else{a=t.oColsNames[e];delete t.customNames[e]}s.view_cols.options[s.view_cols.selectedIndex].text=a;this.parentWindow.Close()}},BX.CDialog.prototype.btnCancel]});e=true}window["renameDialog"+this.table_id].Show();var i=document["rename_"+this.table_id];var s=document["settings_"+this.table_id];if(e)i.appendChild(BX("rename_column_"+this.table_id));var a=s.view_cols.value;i.col_name.focus();i.col_name_def.value=this.oColsNames[a];i.col_name.value=this.customNames[a]?this.customNames[a]:this.oColsNames[a]};this.SaveSettings=function(e,s){var a=document["settings_"+this.table_id];var n="";var l=a.view_cols.length;for(var r=0;r<l;r++)n+=(n!=""?",":"")+a.view_cols[r].value;var o={GRID_ID:this.grid_id,view_id:e,action:i.getUserOptions().getAction("GRID_SAVE_SETTINGS"),sessid:this.vars.sessid,name:a.view_name.value,columns:n,sort_by:a.view_sort_by.value,sort_order:a.view_sort_order.value,page_size:a.view_page_size.value,saved_filter:a.view_filters.value,custom_names:this.customNames,columns_sizes:!a.reset_columns_sizes.checked?this.columnsSizes:{}};if(a.set_default_settings){o.set_default_settings=a.set_default_settings.checked?"Y":"N";o.delete_users_settings=a.delete_users_settings.checked?"Y":"N"}var d=null;if(s===true){d=function(){if(o.saved_filter&&t.oOptions.filters[o.saved_filter]){t.ApplyFilter(o.saved_filter)}else{i.reloadTable()}}}BX.ajax.post("/bitrix/components"+t.vars.component_path+"/settings.ajax.php",o,d);return o};this.ReloadViews=function(){if(t.bViewsChanged)t.Reload()};this.ShowViews=function(){this.bViewsChanged=false;var e=false;if(!window["viewsDialog"+this.table_id]){var i=new BX.CWindowButton({title:this.vars.mess.viewsApply,hint:this.vars.mess.viewsApplyTitle,action:function(){var e=document["views_"+t.table_id];if(e.views_list.selectedIndex!=-1)t.SetView(e.views_list.value);window["bxGrid_"+t.table_id].bViewsChanged=false;this.parentWindow.Close()}});window["viewsDialog"+this.table_id]=new BX.CDialog({content:'<form name="views_'+this.table_id+'"></form>',title:this.vars.mess.viewsTitle,buttons:[i,BX.CDialog.prototype.btnClose],width:this.vars.viewsWndSize.width,height:this.vars.viewsWndSize.height,resize_id:"InterfaceGridViewsWnd"});BX.addCustomEvent(window["viewsDialog"+this.table_id],"onWindowUnRegister",this.ReloadViews);e=true}window["viewsDialog"+this.table_id].Show();var s=document["views_"+this.table_id];if(e)s.appendChild(BX("views_list_"+this.table_id))};this.DragStart=function(){t.onDragStart(this);var e=BX.Main.gridManager.getById(t.grid_id).instance;var i=e.getContainer();var s=e.getTable();var a=e.getRows().getHeadChild()[0].getCells();var n=BX.pos(this);var l=BX.pos(i);var r=n.left-l.left;var o=BX.findChildByClassName(this,"main-grid-cell-head-container",false);this.__cursor=BX.create("div",{props:{className:e.settings.get("classCursor")}});i.appendChild(this.__cursor);o.style.width=this.clientWidth+"px";o.style.height=this.clientHeight+"px";this.__dragNode=document.createElement("DIV");this.__dragNode.className="main-grid-cell-head-drag";this.__dragNode.appendChild(o);BX.style(this.__dragNode,"left",r+"px");s.parentNode.insertBefore(this.__dragNode,s);this.style.height=n.height+"px";this.innerHTML='<span class="main-grid-cell-head-container" style="z-index: 25; "></span>';BX.addClass(this,"main-grid-cell-head-drag-dest");this.__dragDest=this.cellIndex;this.__dragX=r-jsDD.start_x;this.__dragCells=[];for(var d=0;d<a.length;d++){if(a[d].__fixed)continue;var h=BX.pos(a[d]);if(!h.width)continue;var c=BX.findChildByClassName(a[d],"main-grid-cell-head-container",false);BX.addClass(a[d],"main-grid-cell-head-ondrag");this.__cursor.style.left=h.left-l.left+"px";if(d==this.cellIndex){c.style.height=h.height-2+"px";this.__dragCells.ref=this.__dragCells.length}this.__dragCells.push({index:d,node:c,offset:h.left-l.left,width:h.width,move:0})}if(this.__dragCells.length>1&&this.__dragCells.ref==this.__dragCells.length-1){var f=this.__dragCells[this.__dragCells.length-2].index;BX.addClass(a[f],"main-grid-cell-last")}};this.Drag=function(e){var i=this;var s=BX.Main.gridManager.getById(t.grid_id).instance;var a=s.getContainer();var n=e+this.__dragX;var l=BX.pos(a);var r,o,d;this.__dragNode.style.left=n+"px";for(var h=this.__dragCells.length-1;h>=0;h--){if(e-l.left>this.__dragCells[h].offset){this.__dest=this.__dragCells[h].index;break}}r=this.__dragCells.filter(function(e){return e.index==i.__dragDest})[0];o=this.__dragCells.filter(function(e){return e.index==i.__dest})[0];d=o.offset;if(this.__dest>this.__dragDest){d=o.offset+o.width}r.node.style.left=d+"px";this.__cursor.style.left=d+"px"};this.DragStop=function(){t.onDragStop(this);var e=this;var i=BX.Main.gridManager.getById(t.grid_id).instance;var s=i.getRows().getList();var a,n,l,r,o;var d=BX.findChildByClassName(this.__dragNode,i.settings.get("classCellHeadContainer"),false);this.innerHTML="";this.appendChild(d);this.style.height="";BX.removeClass(this,"main-grid-cell-head-drag-dest");BX.remove(this.__cursor);BX.remove(this.__dragNode);s.map(function(t){a=t.getCells();n=a[e.__dragDest];l=a[e.__dest];if(t.isHeadChild()||t.isBodyChild()||t.isFootChild()){if(e.__dest<e.__dragDest){t.getNode().insertBefore(n,l)}if(e.__dest>e.__dragDest){if(BX.type.isDomNode(l.nextElementSibling)){t.getNode().insertBefore(n,l.nextElementSibling)}else{t.getNode().appendChild(n)}}for(var s=0;s<a.length;s++){var r=BX.findChildByClassName(a[s],i.settings.get("classCellHeadContainer"),false);if(r&&r.style){r.style.width="";r.style.left=""}BX.removeClass(a[s],i.settings.get("classCellHeadOndrag"))}}});if(this.__dest!==this.__dragDest){a=i.getRows().getHeadChild()[0].getCells();o=t.oVisibleCols;t.oVisibleCols={};[].forEach.call(a,function(e){r=BX.data(e,"name");if(r){t.oVisibleCols[r]=o[r]}});t.bColsChanged=true;t.SaveColumns()}};this.resizeColumnStart=function(){var e=BX.findParent(this,{className:"main-grid-cell-head"});var s=i.getRows().getHeadFirstChild().getCells();var a=Object.keys(s);var n;t.onDragStart(e);this.__overlay=BX.create("div",{props:{className:"main-grid-cell-overlay"}});BX.append(this.__overlay,e);this.__resizeCell=e.cellIndex;a.forEach(function(e){if(BX.hasClass(s[e],"main-grid-special-empty")){BX.style(s[e],"width","100%")}else{BX.width(s[e],BX.width(s[e]));n=BX.firstChild(s[e]);BX.width(n,BX.width(s[e]))}})};this.resizeColumn=function(e){var s=BX(t.table_id);var a=i.getPinHeader().getFixedTable();var n=s.rows[0].cells[this.__resizeCell];var l,r;var o=BX.pos(s);var d=BX.pos(n);var h=BX.firstChild(n);var c=parseFloat(n.style.width);var f;e-=d.left;f=e;if(d.width>c){e=d.width}e=f>e?f:e;if(e!==d.width){n.style.width=e+"px";h.style.width=e+"px";if(BX.type.isDomNode(a)&&BX.type.isDomNode(a.rows[0])){l=a.rows[0].cells[this.__resizeCell];r=BX.firstChild(l);r.style.width=e+"px";l.style.width=e+"px"}}t.toogleFader()};this.resizeColumnStop=function(){var e=BX(t.table_id);var i=e.rows[0].cells;t.reinitResizeMeta();t.toogleFader();t.onDragStop(i[this.__resizeCell]);BX.remove(this.__resizeCell)};this.onDragStart=function(e){if(e.getAttribute("onclick")){e.setAttribute("data-onclick",e.getAttribute("onclick"));e.removeAttribute("onclick")}};this.onDragStop=function(e){if(e.getAttribute("data-onclick")){setTimeout(function(){e.setAttribute("onclick",e.getAttribute("data-onclick"));e.removeAttribute("data-onclick")},10)}};this.InitFilter=function(){var e=BX("flt_header_"+this.table_id);if(e)jsUtils.addEvent(e,"contextmenu",this.OnRowContext)};this.SwitchFilterRow=function(e,t){if(t){var i=this.menu.GetMenuByItemId(t.id);i.SetItemIcon(t,this.oFilterRows[e]?"":"checked")}else{var s=this.filterMenu[0].MENU;for(var a=0;a<s.length;a++){if(s[a].ID=="flt_"+this.table_id+"_"+e){s[a].ICONCLASS=this.oFilterRows[e]?"":"checked";break}}}var n=BX("flt_row_"+this.table_id+"_"+e);n.style.display=this.oFilterRows[e]?"none":"";this.oFilterRows[e]=this.oFilterRows[e]?false:true;var l=BX("a_minmax_"+this.table_id);if(l&&l.className.indexOf("bx-filter-max")!=-1)this.SwitchFilter(l);this.SaveFilterRows()};this.SwitchFilterRows=function(e){this.menu.PopupHide();var t=0;for(var i in this.oFilterRows){t++;if(t==1&&e==false)continue;this.oFilterRows[i]=e;var s=BX("flt_row_"+this.table_id+"_"+i);s.style.display=e?"":"none"}var a=this.filterMenu[0].MENU;for(t=0;t<a.length;t++){if(t==0&&e==false)continue;if(a[t].SEPARATOR==true)break;a[t].ICONCLASS=e?"checked":""}var n=BX("a_minmax_"+this.table_id);if(n&&n.className.indexOf("bx-filter-max")!=-1)this.SwitchFilter(n);this.SaveFilterRows()};this.SaveFilterRows=function(){var e="";for(var t in this.oFilterRows)if(this.oFilterRows[t])e+=(e!=""?",":"")+t;BX.ajax.get("/bitrix/components"+this.vars.component_path+"/settings.ajax.php?GRID_ID="+this.table_id+"&action=filterrows&rows="+e+"&sessid="+this.vars.sessid)};this.SwitchFilter=function(e){var t=e.className.indexOf("bx-filter-min")!=-1;e.className=t?"bx-filter-btn bx-filter-max":"bx-filter-btn bx-filter-min";e.title=t?this.vars.mess.filterShow:this.vars.mess.filterHide;var i=BX("flt_content_"+this.table_id);i.style.display=t?"none":"";BX.ajax.get("/bitrix/components"+this.vars.component_path+"/settings.ajax.php?GRID_ID="+this.table_id+"&action=filterswitch&show="+(t?"N":"Y")+"&sessid="+this.vars.sessid)};this.ClearFilter=function(e){for(var t=0,i=e.elements.length;t<i;t++){var s=e.elements[t];switch(s.type.toLowerCase()){case"text":case"textarea":s.value="";break;case"select-one":s.selectedIndex=0;break;case"select-multiple":for(var a=0,n=s.options.length;a<n;a++)s.options[a].selected=false;break;case"checkbox":s.checked=false;break;default:break}if(s.onchange)s.onchange()}BX.onCustomEvent(e,"onGridClearFilter",[]);e.clear_filter.value="Y";BX.submit(e)};this.ShowFilters=function(){var e=false;if(!window["filtersDialog"+this.table_id]){var i=new BX.CWindowButton({title:this.vars.mess.filtersApply,hint:this.vars.mess.filtersApplyTitle,action:function(){var e=document["filters_"+t.table_id];if(e.filters_list.value)t.ApplyFilter(e.filters_list.value);this.parentWindow.Close()}});window["filtersDialog"+this.table_id]=new BX.CDialog({content:'<form name="filters_'+this.table_id+'"></form>',title:this.vars.mess.filtersTitle,buttons:[i,BX.CDialog.prototype.btnClose],width:this.vars.filtersWndSize.width,height:this.vars.filtersWndSize.height,resize_id:"InterfaceGridFiltersWnd"});e=true}window["filtersDialog"+this.table_id].Show();var s=document["filters_"+this.table_id];if(e)s.appendChild(BX("filters_list_"+this.table_id))};this.AddFilter=function(e){if(!e)e={};var i="filter_"+Math.round(Math.random()*1e6);var s={name:this.vars.mess.filtersNew,fields:e};this.ShowFilterSettings(s,function(){var e=t.SaveFilter(i);t.oOptions.filters[i]={name:e.name,fields:e.fields};var s=document["filters_"+t.table_id];s.filters_list.options[s.filters_list.length]=new Option(e.name!=""?e.name:t.vars.mess.viewsNoName,i,true,true);if(t.filterMenu.length==4)t.filterMenu=BX.util.insertIntoArray(t.filterMenu,1,{SEPARATOR:true});var a={ID:"mnu_"+t.table_id+"_"+i,TEXT:BX.util.htmlspecialchars(e.name),TITLE:t.vars.mess.ApplyTitle,ONCLICK:"bxGrid_"+t.table_id+".ApplyFilter('"+i+"')"};t.filterMenu=BX.util.insertIntoArray(t.filterMenu,2,a)})};this.AddFilterAs=function(){var e=document.forms["filter_"+this.table_id];var t=this.GetFilterFields(e);this.ShowFilters();this.AddFilter(t)};this.EditFilter=function(e){this.ShowFilterSettings(this.oOptions.filters[e],function(){var i=t.SaveFilter(e);t.oOptions.filters[e]={name:i.name,fields:i.fields};var s=document["filters_"+t.table_id];s.filters_list.options[s.filters_list.selectedIndex].text=i.name!=""?i.name:t.vars.mess.viewsNoName;for(var a=0,n=t.filterMenu.length;a<n;a++){if(t.filterMenu[a].ID&&t.filterMenu[a].ID=="mnu_"+t.table_id+"_"+e){
t.filterMenu[a].TEXT=BX.util.htmlspecialchars(i.name);break}}})};this.DeleteFilter=function(e){if(!confirm(this.vars.mess.filtersDelete))return;var i=document["filters_"+this.table_id];var s=i.filters_list.selectedIndex;i.filters_list.remove(s);i.filters_list.selectedIndex=s<i.filters_list.length?s:i.filters_list.length-1;for(var a=0,n=this.filterMenu.length;a<n;a++){if(t.filterMenu[a].ID&&t.filterMenu[a].ID=="mnu_"+t.table_id+"_"+e){this.filterMenu=BX.util.deleteFromArray(this.filterMenu,a);if(this.filterMenu.length==5)this.filterMenu=BX.util.deleteFromArray(this.filterMenu,1);break}}delete this.oOptions.filters[e];BX.ajax.get("/bitrix/components"+this.vars.component_path+"/settings.ajax.php?GRID_ID="+this.table_id+"&action=delfilter&filter_id="+e+"&sessid="+t.vars.sessid)};this.ShowFilterSettings=function(e,t){var i=false;if(!window["filterSettingsDialog"+this.table_id]){window["filterSettingsDialog"+this.table_id]=new BX.CDialog({content:'<form name="flt_settings_'+this.table_id+'"></form>',title:this.vars.mess.filterSettingsTitle,width:this.vars.filterSettingWndSize.width,height:this.vars.filterSettingWndSize.height,resize_id:"InterfaceGridFilterSettingWnd"});i=true}window["filterSettingsDialog"+this.table_id].ClearButtons();window["filterSettingsDialog"+this.table_id].SetButtons([{title:this.vars.mess.settingsSave,action:function(){t();this.parentWindow.Close()}},BX.CDialog.prototype.btnCancel]);window["filterSettingsDialog"+this.table_id].Show();var s=document["flt_settings_"+this.table_id];if(i)s.appendChild(BX("filter_settings_"+this.table_id));s.filter_name.focus();s.filter_name.value=e.name;this.SetFilterFields(s,e.fields)};this.SetFilterFields=function(e,t){for(var i=0,s=e.elements.length;i<s;i++){var a=e.elements[i];if(a.name=="filter_name")continue;var n=t[a.name]||"";switch(a.type.toLowerCase()){case"select-one":case"text":case"textarea":a.value=n;break;case"radio":case"checkbox":a.checked=a.value==n;break;case"select-multiple":var l=a.name.substr(0,a.name.length-2);var r=false;for(var o=0,d=a.options.length;o<d;o++){var h=t[l]?t[l]["sel"+a.options[o].value]:null;a.options[o].selected=a.options[o].value==h;if(a.options[o].value==h)r=true}if(!r&&a.options.length>0&&a.options[0].value=="")a.options[0].selected=true;break;default:break}if(a.onchange)a.onchange()}};this.GetFilterFields=function(e){var t={};for(var i=0,s=e.elements.length;i<s;i++){var a=e.elements[i];if(a.name=="filter_name")continue;switch(a.type.toLowerCase()){case"select-one":case"text":case"textarea":t[a.name]=a.value;break;case"radio":case"checkbox":if(a.checked)t[a.name]=a.value;break;case"select-multiple":var n=a.name.substr(0,a.name.length-2);t[n]={};for(var l=0,r=a.options.length;l<r;l++)if(a.options[l].selected)t[n]["sel"+a.options[l].value]=a.options[l].value;break;default:break}}return t};this.SaveFilter=function(e){var i=document["flt_settings_"+this.table_id];var s={GRID_ID:this.table_id,filter_id:e,action:"savefilter",sessid:this.vars.sessid,name:i.filter_name.value,fields:this.GetFilterFields(i)};BX.ajax.post("/bitrix/components"+t.vars.component_path+"/settings.ajax.php",s);return s};this.ApplyFilter=function(e){var t=document.forms["filter_"+this.table_id];this.SetFilterFields(t,this.oOptions.filters[e].fields);BX.submit(t)};this.OnDateChange=function(e){var t=false,i=false,s=false,a=false,n=false;if(e.value=="interval")n=t=i=s=true;else if(e.value=="before")i=true;else if(e.value=="after"||e.value=="exact")t=true;else if(e.value=="days")a=true;BX.findNextSibling(e,{tag:"span","class":"bx-filter-from"}).style.display=t?"":"none";BX.findNextSibling(e,{tag:"span","class":"bx-filter-to"}).style.display=i?"":"none";BX.findNextSibling(e,{tag:"span","class":"bx-filter-hellip"}).style.display=s?"":"none";BX.findNextSibling(e,{tag:"span","class":"bx-filter-days"}).style.display=a?"":"none";var l=BX.findNextSibling(e,{tag:"span","class":"bx-filter-br"});if(l)l.style.display=n?"":"none"};this.loadColumn=function(e){var i=BX(this.table_id);var s=this.GetColumnId(e);var a=i.rows[0].cells[s];a.removeAttribute("data-empty");if(a.getAttribute("data-resize"))jsDD.Disable();var n=[];var l=function(l){n.push(l);for(var r in l.edit){if(typeof l.edit[r][e]!="undefined"){if(typeof t.oEditData[r]=="undefined")t.oEditData[r]={};t.oEditData[r][e]=l.edit[r][e]}}if(n.length<t.vars.current_url.length)return;for(var r in n){for(var o in n[r].data){var d=BX("datarow_"+t.table_id+"_"+o).cells[s];BX.findChildByClassName(d,"main-grid-cell-content").innerHTML=n[r].data[o][e]}}if(a.getAttribute("data-resize")){a.removeAttribute("data-resize");var h=i.offsetWidth;var c=a.offsetWidth;t.animation.stop(a);if(a.offsetWidth>0){t.reinitColumnSize(e);var f=a.offsetWidth;a.style.width=c+"px";t.toogleColumnCells(s,true,true);var v={width:{from:c,to:f,unit:"px"}};t.animation(a,v,100,function(){t.toogleColumnCells(s,true,false);t.reinitResizeMeta();t.toogleFader()})}jsDD.Enable()}t.toggleCheckboxes()};for(var r in this.vars.current_url){BX.ajax({url:this.vars.current_url[r],method:"GET",dataType:"json",headers:[{name:"X-Ajax-Grid-UID",value:this.vars.ajax.GRID_AJAX_UID},{name:"X-Ajax-Grid-Req",value:JSON.stringify({action:"showcolumn",column:e})}],onsuccess:l,onfailure:function(){a.setAttribute("data-empty",1);jsDD.Enable()}})}};this.getData=function(e,t){BX.ajax({url:e+(e.indexOf("?")!==-1?"&":"?")+"bxajaxid="+this.vars.ajax.AJAX_ID,method:"GET",dataType:"html",headers:[{name:"X-Ajax-Grid-UID",value:this.vars.ajax.GRID_AJAX_UID},{name:"X-Ajax-Grid-Req",value:JSON.stringify({action:"showpage",columns:this.oVisibleCols})}],processData:true,scriptsRunFirst:true,onsuccess:function(e){t(e)}})}}
//# sourceMappingURL=oldgrid.map.js